<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;
var cardId = null;
var getcardUrl = "/card/get/";
var editcardUrl = "/card/edit/";
var currentcard = null;
$(document).ready(function() {
	cardId = window.dialogArguments;
	$.ajax({
		   type: "GET",
		   url: getcardUrl,
		   data: "cardId=" + cardId,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   var result = data.result;
				   $("#cardId").val(result.cardId);
				   $("#deployId").val(result.deployId);
				   $("#name").val(result.name);
				   $("#desc").val(result.desc);
				   $("#module").val(result.module);
				   $("#catalog").val(result.catalog);
				   $("#type").val(result.type);
				   $("#quality").val(result.quality);
				   $("#award").val(result.award);
				   $("#condition").val(result.condition);
				   $("#nextCardId").val(result.nextCardId);
				   $("#cardres").val(result.cardres);
				   				   
				   currentcard = result; 
				   listselectors();
				   window.returnValue=1;
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
});

function listselectors() {
var getCardSelectorUrl = "/special/Card/getList/";
$.ajax({
		   type: "GET",
		   url: getCardSelectorUrl,
		   data: "",
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   selectnextCardId(s2json(data.result));
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

function editcard() {
	var cardIdParam = "cardId=" + cardId;
	var nameValue = $("#name").val();
	if(!checkString("名字",nameValue,false)) {
		return;
	}
	var nameParam = "name=" + xparseString(nameValue);
		
	var descValue = $("#desc").val();
	if(!checkString("描述",descValue,false)) {
		return;
	}
	var descParam = "desc=" + xparseString(descValue);
		
	var moduleValue = $("#module").val();
	
	var moduleParam = "module=" + moduleValue;
		
	var catalogValue = $("#catalog").val();
	if(!checkInteger("目录",catalogValue,false)) {
		return;
	}
	var catalogParam = "catalog=" + xparseInt(catalogValue);
		
	var typeValue = $("#type").val();
	if(!checkInteger("分类",typeValue,false)) {
		return;
	}
	var typeParam = "type=" + xparseInt(typeValue);
		
	var qualityValue = $("#quality").val();
	
	var qualityParam = "quality=" + qualityValue;
		
	var awardValue = $("#award").val();
	
	var awardParam = "award=" + awardValue;
		
	var conditionValue = $("#condition").val();
	
	var conditionParam = "condition=" + conditionValue;
		
	var nextCardIdValue = $("#nextCardId").val();
	
	var nextCardIdParam = "nextCardId=" + nextCardIdValue;
		
	var cardresValue = $("#cardres").val();
	
	var cardresParam = "cardres=" + cardresValue;
			
	$.ajax({
		   type: "POST",
		   url: editcardUrl,
		   		   data:  cardIdParam + '&' +  nameParam  +'&'+   descParam  +'&'+   moduleParam  +'&'+   catalogParam  +'&'+   typeParam  +'&'+   qualityParam  +'&'+   awardParam  +'&'+   conditionParam  +'&'+   nextCardIdParam  +'&'+   cardresParam  ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			   	   beforeWindowClose();
				   window.close();
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

	
	
	
	
	
	
			function addaward() {
			var awardstr = $('#award').val();
			var returnCallback = function(retvalue) {
				$('#award').val(retvalue);
			}
			openDialog("/pages/customer/RewardEntity.html",awardstr,"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function addcondition() {
			var conditionstr = $('#condition').val();
			var returnCallback = function(retvalue) {
				$('#condition').val(retvalue);
			}
			openDialog("/pages/customer/ConditionEntity.html",conditionstr,"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function selectnextCardId(options) {
			var optionHTML = "";
			for(var i in options) {
				optionHTML = optionHTML + "<option value='"+ options[i][0] +"'>" + options[i][1] + "</option>\n";
			}
			$("#nextCardId").html(optionHTML);
			if(currentcard != undefined) {
				$("#nextCardId").val(currentcard.nextCardId);
			}
		}
	
	
function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("card",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/card/add" method="post">
		<table>
			<tbody>
				<tr>
					<td>ID</td><td><input type="text" id="cardId" name="cardId" disabled/></td>
					<td>发布Id</td><td><input type="text" id="deployId" name="deployId" disabled/></td>
				</tr>
			</tbody>
		</table>
		<table>
			<tbody>				
					<tr>					<td>
						<label for="name" id="lbl_name">名字</label>
													<input type="text" id="name" name="name" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="desc" id="lbl_desc">描述</label>
													<input type="text" id="desc" name="desc" /><span class="tips">[文字]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="module" id="lbl_module">模块</label>
																				<select id="module" name="module">
								
									<option value="1">成就图鉴</option>
								
									<option value="2">英雄图鉴</option>
								
									<option value="3">装备图鉴</option>
								
									<option value="4">剧情图鉴</option>
															</select>
											</td>
									
										<td>
						<label for="catalog" id="lbl_catalog">目录</label>
													<input type="text" id="catalog" name="catalog" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="type" id="lbl_type">分类</label>
													<input type="text" id="type" name="type" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="quality" id="lbl_quality">边框颜色</label>
																				<select id="quality" name="quality">
								
									<option value="1">黑色</option>
								
									<option value="2">银色</option>
								
									<option value="3">金色</option>
								
									<option value="4">彩色</option>
															</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="award" id="lbl_award">奖励</label>
													<input type="text" id="award" name="award" value="{}" disabled/>
							<input type="button" value="..." onclick="addaward()"/>
											</td>
									
										<td>
						<label for="condition" id="lbl_condition">完成条件</label>
													<input type="text" id="condition" name="condition" value="{}" disabled/>
							<input type="button" value="..." onclick="addcondition()"/>
											</td>
					</tr>				
					<tr>					<td>
						<label for="nextCardId" id="lbl_nextCardId">下一个图鉴</label>
													<select id="nextCardId" name="nextCardId">
							</select>
											</td>
									
										<td>
						<label for="cardres" id="lbl_cardres">资源SWF</label>
													<input type="text" id="cardres" name="cardres" disabled/>
							<input type="button" value="..." onclick="openResource('cardres','')"/><span class="tips">[资源]</span>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="editcard()" value="修改"/>
	</form>
	</div>
</body>